using System.Diagnostics.CodeAnalysis;
using System.Web.Mvc;
using System.Web.Routing;
using StructureMap;

namespace Coderoom.ScrumPlanner.Web
{
	public sealed class StructureMapControllerFactory : DefaultControllerFactory
	{
		[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter")]
		public TController CreateController<TController>() where TController : class
		{
			return CreateController(null, typeof (TController).Name.Replace("Controller", string.Empty)) as TController;
		}

		public override IController CreateController(RequestContext requestContext, string controllerName)
		{
			var key = controllerName;
			return ObjectFactory.GetNamedInstance<Controller>(key);
		}
	}
}